<style lang="less">
    .ivu-select-dropdown {
        z-index: 10086;
    }
</style>
<template>
    <Drawer :closable="false" placement="right" v-model="drawerVisible" width="45%" :title="drawerTitle">
        <Row>
            <Form ref="form" :model="form" :label-width="100" :rules="formValidate" style="position:relative">
                <FormItem label="考试场次名称" prop="childexamName">
                    <Input v-model="form.childexamName" style="width:600px"/>
                </FormItem>
                <!--<FormItem label="考试日期" prop="examTimeDate">
                    <DatePicker type="date" format="yyyy-MM-dd"  @on-change="dataChange" :value="form.examTimeDate" style="width:300px" placeholder="请输入考试日期"></DatePicker>
                </FormItem>
                <FormItem label="可报名人数" prop="signCount">
                    <Input v-model="form.signCount" type="number" :min="1" style="width:300px"/>
                </FormItem>
                <FormItem label="考试时间" prop="examStartTime">
                    <TimePicker type="timerange" format="HH:mm:ss"  @on-change="selectDateRange" :value="[form.examStartTime,form.examendTime]" style="width:300px" placeholder="请输入报名时间"></TimePicker>
                </FormItem>-->
                <Form-item class="br">
                    <Button type="primary" :loading="submitLoading" @click="handelSubmit" style="width:100px">提交</Button>
                    <Button @click="handelCancel">取消</Button>
                </Form-item>
                <Spin size="large" fix v-if="loading"></Spin>
            </Form>
        </Row>
    </Drawer>
</template>
<script>
    import {sessionsEdit} from "@/api/bus";
    // 表情包配置 自定义表情可在该js文件中统一修改
    import {sina} from "@/libs/emoji";

    export default {
        name: "sessions-drawer",
        components: {
        },
        data() {
            return {
                type: 0,
                loading: false, // 表单加载状态
                drawerTitle: "编辑考试安排",
                drawerVisible: false,
                form: {
                    childexamName: '',
                    examTimeDate: '',
                    signCount: 1,
                    examStartTime: '',
                    examendTime: ''
                },
                formValidate: {
                    childexamName: [{required: true, message: "场次名称不能为空", trigger: "blur"}]
                },
                submitLoading: false, // 添加或编辑提交状态
                dataEdit: "", // 编辑数据
            };
        },
        methods: {
            init() {
            },
            getForm(){
                this.form.id ='';
                this.form.examinationId = ''
                this.form.examTimeDate = ''
                this.form.signCount = 1
                this.form.signlastCount = 0
                this.form.examStartTime = ''
                this.form.examendTime = ''
                this.form.childexamName = ''
                this.form.status = 0
            },
            showDrawer(params) {
                if(params.id){
                    this.drawerTitle="编辑场次安排";
                    this.form.id = params.id;
                    this.form.examinationId = params.examinationId
                    this.form.examTimeDate = params.examTime
                    this.form.signCount = params.signCount
                    this.form.signlastCount = params.signlastCount
                    this.form.examStartTime = params.examStartTime
                    this.form.examendTime = params.examendTime
                    this.form.childexamName = params.childexamName
                    this.form.status = params.status
                }else{
                    this.getForm()
                    this.drawerTitle="新增场次安排";
                    this.form.examinationId = params.examinationId
                }
                this.drawerVisible = true;
            },
            dataChange(v){
                if (v) {
                    this.form.examTimeDate = v;
                }
            },
            selectDateRange(v) {
                if (v) {
                    this.form.examStartTime = v[0];
                    this.form.examendTime = v[1];
                }
            },
            handelSubmit() {
                this.$refs.form.validate(valid => {
                    if (valid) {
                        this.submitLoading = true;
                        // 编辑
                        sessionsEdit(this.form).then(res => {
                            this.submitLoading = false;
                            if (res.status === true) {
                                this.$Message.success("操作成功");
                                this.$parent.getDataList();
                                this.drawerVisible = false;
                            }
                        });
                    }
                });
            },
            handelCancel() {
                this.drawerVisible = false;
            }
        },
        mounted() {
            this.init();
        },
        watch: {

        }
    };
</script>